package com.jinsi.controller.yrf;


import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.jinsi.constant.YrfConstant;
import com.jinsi.pojo.VersionManagement;
import com.jinsi.service.yrf.BackgroundVersionManagementService;
import com.jinsi.util.R;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.util.Date;
import java.util.List;

/**
 * @author: 86185
 * @description: 后台版本管理
 * @date 2022/9/12
 */
@RestController
@RequestMapping("/backgroundVersionManagement")
public class BackgroundVersionManagementController {

    private static Logger logger = LoggerFactory.getLogger(BackgroundVersionManagementController.class);
    @Autowired
    private BackgroundVersionManagementService backgroundVersionManagementService;

    /**
     *
     * @param page 分页
     * @param limit 分页
     * @param versionNumber 模糊查
     * @param versionCreator 模糊查
     * @param versionCreationTime 模糊查
     * @return 状态码
     */
    @RequestMapping("/getAll")
    public R getAll(Integer page, Integer limit, Integer versionNumber, String versionCreator, Date versionCreationTime){

        PageHelper.startPage(page,limit);
        List<VersionManagement> all = backgroundVersionManagementService.getAll(versionNumber,versionCreator,versionCreationTime);
        PageInfo<VersionManagement> pageInfo = new PageInfo<>(all);

        return R.custom(YrfConstant.LAYUI_CODE,
                YrfConstant.LAYUI_MSG,
                pageInfo.getList(),
                pageInfo.getTotal());

    }

    /**
     * 添加后台版本管理的版本
     * @param ver 添加版本
     */
    @RequestMapping("/add")
    public R backgroundVersionManagementadd(@Valid VersionManagement ver){
        logger.info("添加了一个版本 --- >"+ver.getAppName());
        backgroundVersionManagementService.backgroundVersionManagementadd(ver);
        return R.ok("成功");

    }
}
